package com.myidis.mapper;

import java.util.ArrayList;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.myidis.entity.Quota;

public interface QuotaMapper {
	@Select("SELECT * FROM quota")
    @Results({
    	@Result(property = "id", column = "id"),
    	@Result(property = "code", column = "code"),
        @Result(property = "chineseName", column = "chinese_name"),
        @Result(property = "englishName", column = "english_name"),
        @Result(property = "description", column = "description"),
        @Result(property = "freqMonth", column = "freq_month"),
        @Result(property = "freqSeason", column = "freq_season"),
        @Result(property = "freqYear", column = "freq_year"),
        @Result(property = "composite", column = "composite"),
        @Result(property = "typeId", column = "type"),
        @Result(property = "deptId", column = "dept")
    })
    ArrayList<Quota> all();

	@Select("SELECT chinese_name,id FROM quota")
	@Results({
			@Result(property = "id", column = "id"),
			@Result(property = "chineseName", column = "chinese_name")
	})
	ArrayList<Quota> allName();
	
	@Select("SELECT * FROM quota WHERE id = #{id}")
	@Results({
			@Result(property = "id", column = "id"),
			@Result(property = "code", column = "code"),
			@Result(property = "chineseName", column = "chinese_name"),
			@Result(property = "englishName", column = "english_name"),
			@Result(property = "description", column = "description"),
			@Result(property = "freqMonth", column = "freq_month"),
			@Result(property = "freqSeason", column = "freq_season"),
			@Result(property = "freqYear", column = "freq_year"),
			@Result(property = "composite", column = "composite"),
			@Result(property = "typeId", column = "type"),
			@Result(property = "deptId", column = "dept")
	})
	Quota getOne(int id);

//	@Select("SELECT * FROM quota WHERE quota = #{id}")
//	@Results({
//			@Result(property = "id", column = "id"),
//			@Result(property = "code", column = "code"),
//			@Result(property = "chineseName", column = "chinese_name"),
//			@Result(property = "englishName", column = "english_name"),
//			@Result(property = "description", column = "description"),
//			@Result(property = "freqMonth", column = "freq_month"),
//			@Result(property = "freqSeason", column = "freq_season"),
//			@Result(property = "freqYear", column = "freq_year"),
//			@Result(property = "composite", column = "composite"),
//			@Result(property = "typeId", column = "type"),
//			@Result(property = "deptId", column = "dept")
//	})
//	Quota getName(int id);
	
	@Insert("INSERT INTO quota(code, chinese_name, english_name, description, freq_month, freq_season, freq_year, composite, type, dept) VALUES(#{code}, #{chineseName}, #{englishName}, #{description}, #{freqMonth}, #{freqSeason}, #{freqYear}, #{composite}, #{typeId}, #{deptId})")
    int insert(Quota quota);

    @Update("UPDATE quota SET id = #{id}, code = #{code}, chinese_name = #{chineseName}, "
    		+ "english_name = #{englishName}, description = #{description}, freq_month = #{freqMonth},"
    		+ "freq_season = #{freqSeason},freq_year = #{freqYear},composite = #{composite},"
    		+ "type = #{typeId},dept = #{deptId} WHERE id = #{id}")
    int update(Quota quota);

    @Delete("DELETE FROM quota WHERE id = #{id}")
    int delete(int id);
}
